<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\behavior;

use think\Db;

class memberRegStatis extends \think\Controller {

   

    public function run() {



        // 用户增涨30天内之内
        // select count(id) as count,FROM_UNIXTIME(create_time, '%Y-%m-%d') as mydate from tb_member group by FROM_UNIXTIME(create_time, '%Y-%m-%d')
        $month_start = time() - 3600 * 24 * 30;
        $sql = "select count(id) as count,FROM_UNIXTIME(create_time, '%Y-%m-%d') as mydate from tb_member where create_time > " . $month_start . " group by FROM_UNIXTIME(create_time, '%Y-%m-%d') ";
        $member_count_this_month_group = Db::query($sql);

        //基数是多少
        $member_count_last_month_base = db('member')->where('create_time', '<', $month_start)->count();

        $member_count_this_month_group_result = [];
        foreach ($member_count_this_month_group as $key => $value) {

            $addup = 0;
            for ($i = 0; $i <= $key; $i++) {
                $addup += (int) $member_count_this_month_group[$i]['count'];
            }

            $member_count_this_month_group_result[$key]['count'] = $member_count_last_month_base + $addup;
            $member_count_this_month_group_result[$key]['date'] = $value['mydate'];
        }

        echo $this->fetch('behavior/member_reg_statis', ['member_count_this_month_group_result'=>$member_count_this_month_group_result]);
    }

}
